var ns, app,superFile,imageBrowser;
app = new Vue({
    el: '#app',
    data: {
        ID: 0,
        showdetail:false,
        form:{},
        showmore:false,
        moreContent:'',
        moreName:'',
     
    },
    methods: {
        get_data: function () {
            var that = this;
            var options = {};
            options.ID = that.ID;
            options.action = "getuserstaffoutcontract";
            ns.post(options, function (succeed, data, err) {
                console.log(JSON.stringify(data));
                if (succeed) {
                    if(data.status){
                        that.form = data.ContractInfo;
                    }else{
                        api.toast({
                            msg: '接口错误',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });

                }
            }, {
                toast: true
            });
        },
       
        //合同审批-展开详细信息
        open_all:function(){
            var that=this;
            that.showdetail=true;
        },
        //合同审批-关闭详细信息，展示关键信息
        close_all:function(){
            var that=this;
            that.showdetail=false;
        },
         //外包单位详情
         othercomputer_detail:function(id){
            var that=this;
            ns.openWin('othercomputer_detail', '外包单位详情', {
                ID: id,
            });
        },
        do_viewimages: function (activeIndex) {
            var that = this;
            var imageUrls = [];
            for (var i = 0; i < that.form.Picture.length; i++) {
                imageUrls.push(that.form.Picture[i].ImgPath);
            }
            var imageBrowser = api.require('imageBrowser');
            imageBrowser.openImages({
                showList: false,
                activeIndex: activeIndex,
                imageUrls: imageUrls
            });
        },
        set_value:function(value){
            if(value&&value.length>30){
                value=value.substring(0,30)+'...';
            }
            return value;
        },
        open_more:function(item){
            var that=this;
            that.showmore=true;
            that.moreContent=item.AcceptCont;
            that.moreName=item.AcceptName;
        },
        //打开文件
        open_flie:function(item){
            console.log('ddd');
            var that=this;
            if(item.TypeName=='png'||item.TypeName=='jpg'||item.TypeName=='tif'||item.TypeName=='gif'){
                that.img_browser(item.FilePath);
            }else if(item.TypeName=='mp4'||item.TypeName=='wmv'||item.TypeName=='rmvb'||item.TypeName=='avi'){
                that.open_video(item);
            }else if(item.TypeName == 'rar'){
                that.down_fire(item);
            }else{
                that.do_openFile(item);
            }
        },
        // 下载压缩文件
        down_fire:function(item){
            var that=this;
            api.download({
                url: item.FilePath,
                savePath: 'fs://app/' + item.FileName,
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {
                if (ret.state == 1) {
                    api.toast({
                        msg: '已下载至手机文件夹',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
        },
        // 播放视频
        open_video: function (item) {
            var that = this;
            var module = api.require('easyVideoPlayer');
            var param = {
                msg: item.FilePath
            };
            api.download({
                url: item.FilePath,
                savePath: 'fs://app/' + item.FileName,
                report: true,
                cache: true,
                allowResume: true
            }, function (ret, err) {
                if (ret.state == 1) {
                    module.playVideo(param);
                }
            })
        },
        img_browser: function(imgurl) {
            var that = this;
            var imgurls = [];
            imgurls.push(imgurl);
            imageBrowser.openImages({
                imageUrls: imgurls,
                showList: false,
                activeIndex: 0
            });
        },
        do_openFile:function(item){
            var that=this;
            api.download({
                url:item.FilePath,
                savePath:'fs://app/'+item.ImgName,
                report:true,
                cache:true,
                allowResume:true
            }, function(ret, err){
                if(ret.state==1){
                    if(api.systemType=="android"){
                        superFile.open({
                            path:ret.savePath,
                        })
                    }
                }
            })
        },
       

    }
});
apiready = function () {
    api.parseTapmode();
    superFile = api.require('superFile');
    if (api.systemType == "android") {
        superFile.init(function(ret){});
    }
    imageBrowser = api.require('imageBrowser');
    ns = window.Foresight.Util;
    app.ID = api.pageParam.ID;
    app.get_data();
};
